﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Diagnostics;

namespace HSIA
{
    static class Program
    {
        [STAThread]
        static void Main()
        {
            Process Proc = AIIS();

            if (Proc == null)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new FrmMain());
            }
            else
            {
                BIIS(Proc);
            }
        }

        public static Process AIIS()
        {
            Process current = Process.GetCurrentProcess();
            Process[] processes = Process.GetProcessesByName(current.ProcessName);
            foreach (Process process in processes)
            {
                if (process.Id != current.Id && process.MainModule.FileVersionInfo.FileVersion == current.MainModule.FileVersionInfo.FileVersion)
                {
                    if (System.Reflection.Assembly.GetExecutingAssembly().Location.Replace("/", "\\") == current.MainModule.FileName)
                    {
                        return process;
                    }
                }
            }
            return null;
        }

        public static void BIIS(Process Proc)
        {
            PC.ShowWindow(Proc.MainWindowHandle, 9);
            PC.SetForegroundWindow(Proc.MainWindowHandle);
            //Proc.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
            //ShowWindowAsync(instance.MainWindowHandle, 1);
            //SetForegroundWindow(instance.MainWindowHandle);
        }
    }
}